<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Models\AuthenticLog;
use App\Models\Category;
use App\Models\Config;
use App\Models\Goods;
use App\Models\GoodsDepict;
use App\Models\GoodsSetmeal;
use App\Models\GoodsSpec;
use App\Models\MemberLegal;
use App\Models\MemberOther;
use App\Models\OrderGoods;
use App\Models\OrderRadarBoolea;
use App\Models\OrderRate;
use App\Models\OrderRemark;
use App\Models\OrderReturn;
use App\Models\OrderRiskBoolea;
use App\Models\OtherOrder;
use App\Models\OtherOrderAllocate;
use App\Models\OtherWithholdLog;
use App\Models\RiskCredit;
use App\Models\SaleUser;
use App\Models\ShopSms;
use App\Models\ShopUser;
use App\Models\Order;
use App\Models\OrderLease;
use App\Models\Complain;
use App\Models\SmsRecord;
use App\Models\SmsTemplate;
use App\Models\Source;

use App\Services\AlipayService;
use App\Services\AntchainService;
use App\Services\BaofupayService;
use App\Services\BaofuWithdrawPayService;
use App\Services\BuErService;
use App\Services\ChargeService;
use App\Services\CommonService;
use App\Services\CreditCallService;
use App\Services\EducationService;
use App\Services\EsignService;
use App\Services\GoodsService;
use App\Services\HuifupayService;
use App\Services\InteractiveRiskQueryService;
use App\Services\NotarizeService;
use App\Services\RelationVerifyService;
use App\Services\SafeService;
use App\Services\SmsService;
use App\Services\StrategyService;
use App\Services\RadarService;
use App\Services\RiskService;
use App\Services\CreditService;
use App\Services\OrderService;
use App\Services\XinyanService;
use Illuminate\Http\Request;
use App\Models\OrderCredit;
use Illuminate\Support\Facades\Redis;
use function Psy\debug;
use Illuminate\Support\Facades\DB;
use App\Services\AlipayMessageService;
use App\Services\AliyunSmsService;
use App\Services\AntchainPlusService;
use App\Services\YpcreditService;
use App\Services\BairaongService;
use App\Services\WechatService;
use App\Services\AlipayRiskService;
use App\Services\AntchainAtoService;
use App\Services\AlipayRealpersonService;


class TestController extends Controller
{
    public function iphoneCountList(Request $request){

        if(strtotime($request['start_time'])>strtotime($request['end_time'])){
            exit('开始时间不能大于结束时间');
        }
        if(!$request['start_time']||!$request['end_time']){
            exit('请选择时间');
        }

        $interval=floor((strtotime($request['end_time'])-strtotime($request['start_time']))/86400);
        for($i=0;$i<=$interval;$i++){
                $count=Order::from('sp_order_2 as o')
                ->where('o.phone_brand','like','%'.'iPhone'.'%')
                ->where('m.cert_name','<>','0')
                ->where('o.create_time','<',strtotime($request['start_time'])+($i+1)*86400)
                ->where('o.create_time','>',strtotime($request['start_time'])+$i*86400)
                ->where('o.status','<',10)
                ->where('m.is_use',0)
                ->leftjoin('sp_member_2 as m', 'o.uid', 'm.id')
                ->distinct('m.mobile')
                ->select('m.mobile','m.cert_name','m.cert_no','o.trade_no','o.phone_brand','o.trade_no','o.status',
                    'o.id','o.begin_time','o.end_time','o.create_time')
                ->orderBy('m.id','desc')
                ->count();
                echo '时间'.date('Y-m-d',strtotime($request['start_time'])+$i*86400).'：'.$count.'<br/>';
          }
        exit();
    }
    //苹果设备
    public function iphoneList(Request $request){

        if(strtotime($request['start_time'])>strtotime($request['end_time'])){
            exit('开始时间不能大于结束时间');
        }
        if(!$request['start_time']||!$request['end_time']){
            exit('请选择时间');
        }
        $user= Order::from('sp_order_2 as o')
            ->where('o.phone_brand','like','%'.'HONOR'.'%')
            ->where('m.cert_name','<>','0')
            ->where('o.create_time','<',strtotime($request['end_time'])+86399)
            ->where('o.create_time','>',strtotime($request['start_time']))
            ->where('o.status','<',10)
            ->where('m.is_use',0)
            ->leftjoin('sp_member_2 as m', 'o.uid', 'm.id')
            ->groupBy('m.mobile')
            ->select('m.mobile','m.cert_name','m.cert_no','o.trade_no','o.phone_brand','o.trade_no','o.status',
                'o.id','o.begin_time','o.end_time','o.create_time')
            ->orderBy('m.id','desc')
            ->offset(0)
            ->limit(500)
            ->get()->toArray();
        $num = 0;
        foreach ($user as $key=>$value) {
            $dataInfo[$key][] = $value['phone_brand'];
            $dataInfo[$key][] = $value['mobile'];
            $dataInfo[$key][] = $value['cert_name'];
            $dataInfo[$key][] = date('Y-m-d H:i:s',$value['create_time']);
//           MemberOther::where('cert_no',$value['cert_no'])->update(['is_use'=>1]);
        }

        $headList = [
            '设备型号',
            '手机号码',
            '姓名',
            '下单时间',
        ];

        $title = "华为设备数据".$request['start_time'].'至'.$request['end_time'];

        //调用上面的方法
        return  csvExporta($dataInfo, $headList, $title);
        exit();
    }
    public function zlbtest(Request $request){


        set_time_limit(0);
        // 设置日志文件的路径
        $logFilePath = '/www/wwwroot/www.doulaizu.com/exported_loga.log';

// 使用file()函数读取文件到数组中
        $logLines = file($logFilePath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
//var_dump($logLines);
// 处理数组中的每一行
        $logEntries = array();
        foreach ($logLines as $line) {
            // 根据日志格式解析每一行，这里只是简单地分割成数组
            $logEntry = explode(' ', $line);
            $logEntries[] = $logEntry;
        }
        foreach ($logEntries as $ra){

//            dd(str_replace('[', '', $ra[3]));
            $dateString=str_replace('[', '', $ra[3]).' +0800';
//            $timezone = new DateTimeZone('Asia/Shanghai'); // 设置正确的时区
            $dateTime = \DateTime::createFromFormat('d/M/Y:H:i:s P', $dateString);
            $time = $dateTime->getTimestamp();
            if($ra[6]=='/extenda.html'){
                $sale_user_id='012418205971';
            }
            if($ra[6]=='/extendb.html'){
                $sale_user_id='012610455071';
            }
            if($ra[6]=='/extendc.html'){
                $sale_user_id='012610463751';
            }
            if($ra[6]=='/extend.html'){
                $sale_user_id='012418193027';
            }
            $arr=['sale_user_id'=>$sale_user_id??0,'ip'=>$ra[0],'create_time'=>$time];
            Db::table('sp_extension_statistics')->insert($arr);
        }

        return $logEntries;
//
//        $result=WechatService::get_order_list();
//        $result=json_decode($result['data'],true);
//        if($result['order_list']){
//            foreach ($result['order_list'] as $ra){
//
//                $where=[];
//                $where[] =['ol.trade_no', $ra['transaction_id']];
//                $where[] =['m.openId', '<>',''];
//                $order = Order::from('sp_order_2 as o', 'o.id', 'ol.order_id')
//                    ->leftjoin('sp_order_goods_2 as og', 'o.id', 'og.order_id')
//                    ->leftjoin('sp_order_lease_2 as ol', 'o.id', 'ol.order_id')
//                    ->leftjoin('sp_goods_2 as g','og.goods_id','g.id')
//                    ->leftjoin('sp_member_2 as m', 'o.uid', 'm.id')
//                    ->select(
//                        'm.openId', 'ol.out_order_no','o.id','o.trade_no','o.location','o.status','ol.which_period',
//                        'o.is_insurance_choose_custom','o.remark', 'o.realname', 'o.mobile as address_mobile', 'o.address', 'o.order_from'
//                        , 'og.goods_title',  'og.setmeal_title', 'og.is_buy_out', 'og.device_number', 'og.pact_type','og.setmeal_foregift','og.setmeal_price'
//                        , 'm.mobile',
//                    )->where($where)->orderBy('id','asc')->first();
//
//                if($order&&$order['openId']&&$order['which_period']>1){
//                    $order['out_order_no']=$ra['transaction_id'];
//                    return  WechatService::upload_shipping_info_lease($order,$order['which_period']);
//                }
//            }
//        }
//
//        return 0;

//        $count= Order::from('sp_order_2 as o')
//            ->whereIn('o.sale_user_id',['012418193027','012418205971','012610455071','012610463751'])
//            ->where('o.seller_id','<>','202309081070080001')
//            ->count();
//        return $count;
               //导出核对数据
       $usera= Order::from('sp_order_2 as o')
       ->whereIn('o.status',[60])
       ->leftjoin('sp_member_2 as m','m.id','o.uid')
       ->leftjoin('sp_order_lease_2 as ol','ol.order_id','o.id')
       ->select('m.mobile','m.cert_name','m.cert_no','o.trade_no','m.id','o.status','o.create_time')
       ->distinct('m.id')
       ->limit(10)
       ->orderBy('ol.pay_time','desc')
       ->get()->toArray();

        $userb= Order::from('sp_order_2 as o')
            ->where('o.status',39)
            ->leftjoin('sp_member_2 as m','m.id','o.uid')
            ->leftjoin('sp_order_lease_2 as ol','ol.order_id','o.id')
            ->select('m.mobile','m.cert_name','m.cert_no','o.trade_no','m.id','o.status','o.create_time')
            ->distinct('m.id')
            ->limit(10)
            ->get()->toArray();

        $user=array_merge($usera,$userb);

//        shuffle($user);

        $num = 0;
        $dataInfo=[];
        foreach ($user as $key=>$value) {
            $dataInfo[$key][] = $key;
            $dataInfo[$key][] = " ".$value['trade_no']."\t";
            $dataInfo[$key][] = $value['cert_name'];
            // 日期
            $dataInfo[$key][] =" ".$value['cert_no']."\t";
            // 序号
            $dataInfo[$key][] = " ".$value['mobile']."\t";
            $dataInfo[$key][] = OrderService::getOrderStatusName($value['status']);
//            $dataInfo[$key][] =hash("sha256", $value['cert_no']);
//            $dataInfo[$key][] =date('Y-m-d',$value['create_time']);
        }

        $headList = [
            '序号',
            '订单号',
            '姓名',
            '身份证',
            '手机号',
            '状态',
//            'sha256加密后的身份证号码',
//            '下单时间',
        ];

        $title = "导出cvs数据";

        //调用上面的方法
        return csvExporta($dataInfo, $headList, $title);

//       exit();
//
////dd($order);
//       foreach ($order as $ra) {
//           $object = 'https://img.qianbaozuji.com/' . $ra['pact_url'];
//           var_dump($object);
//           $file = file_get_contents($object);
//           $path = dirname(dirname(dirname(dirname(dirname(__FILE__))))) . '/storage/tmp/concact/' . $ra['cert_name'].'.pdf';
//           //               dd($path);
//           $res = file_put_contents($path, $file);
////        dd($res);
//       }
//exit();

        //推单
//        $order = Order::from('sp_order_2 as o', 'o.id', 'ol.order_id')
//            ->leftjoin('sp_member_2 as m', 'o.uid', 'm.id')
//            ->select(
//                'o.face_flow_id', 'o.id','o.trade_no','o.location','o.status',
//                'o.uid',
//            )->where('m.contract_no','<>','')->where('o.status',4)->where('o.username','admin')->where('o.face_flow_id','<>','')->orderBy('id','desc')->get();
//
//        $order=$order->toArray();
//        foreach ($order as $ra){
//            //推单
//
//            $contextId = $ra['uid'];
//            $log['order_id']=$ra['id'];
//            if($log['order_id']){
//                $ordercount=Order::from('sp_order_2 as o')
//                    ->where('o.uid',$contextId)
//                    ->where('u.contract_no','<>','')
//                    ->leftjoin('sp_member_2 as u','o.uid','u.id')
//                    ->count();
//                if($ordercount==1){
//
//                    $otherMember=OtherOrderAllocate::whereRaw('weight > timecate')->orderBy('id', 'desc')->first();
//                    $otherMember = obToArray($otherMember);
//
//                    if(empty($otherMember)){
//                        OtherOrderAllocate::where('timecate','>',0)->update(['timecate'=>0]);
//                        $otherMember=OtherOrderAllocate::whereRaw('weight > timecate')->orderBy('id', 'desc')->first();
//                        $otherMember = obToArray($otherMember);
//                    }
//
//                    if($ordercount&&$otherMember){
//                        if($otherMember['limit']){
//                            $order_limit_count=OtherOrder::where('member_id',$otherMember['member_id'])->whereDate('created_at', date('Y-m-d'))->count();
//                            if($order_limit_count>=$otherMember['limit']){
//                                $otherMember=OtherOrderAllocate::whereRaw('limit = 0')->first();
//                            }
//                        }
//
//                        OtherOrderAllocate::where('id',$otherMember['id'])->increment('timecate');
//                        $isSendOther=$otherMember['member_id']?1:0;
//                    }else{
//                        return $request_data;
//                    }
//
//                    $otherMember && OtherOrderAllocate::where('id',$otherMember['id'])->increment('totalcate');
//
//
//                    $order_data= Order::from('sp_order_2 as o')->where('o.id',$log['order_id'])->leftjoin('sp_order_goods_2 as og','o.id','og.order_id')->first();
//                    $order_lease_data=OrderLease::where('order_id',$log['order_id'])->get();
//                    $order_lease_data=obToArray($order_lease_data);
//                    $member = MemberOther::where('id',$contextId)->first();
//                    $orderGoods=OrderGoods::where('order_id',$log['order_id'])->select('goods_id','setmeal_id')->first();
//                    $goods = Goods::GoodsInfo($orderGoods['goods_id']);
//                    $setmeal = GoodsSetmeal::getGoodsSetmealInfo($orderGoods['setmeal_id']);
//                    $spec=GoodsSpec::GetSpecList($orderGoods['setmeal_id'],$orderGoods['goods_id']);
//                    $order_goods_data['goods']  = $goods;
//                    $order_goods_data['goods_setmeal']  = $setmeal;
//                    $order_goods_data['goods_spec'] =$spec;
//
//
//                    if($isSendOther){
//                        $order_data['order_form']='wechat';
//                        $add_remark = [
//                            'uid'=>'23',
//                            'username'=>'同步',
//                            'create_time'=>time(),
//                            'remark'=>'订单已推给其他平台'.$otherMember['name_tit'],
//                            'order_id'=>$log['order_id']
//                        ];
//                        OrderRemark::insert($add_remark);
//                        Order::where('id',$log['order_id'])->update(['username'=>'admin']);
//                    }
//
//                    $OtherOrder=[
//                        'order_data'=>json_encode($order_data),
//                        'order_lease_data'=>json_encode($order_lease_data),
//                        'goods_data'=>json_encode($order_goods_data),
//                        'member_data'=>json_encode($member->toArray()),
//                        'remark_data'=>'[]',
//                        'member_id'=>$otherMember['member_id'],
//                        'order_id'=>$log['order_id'],
//                        'status'=>1,
//                        'is_allocate'=>1,
//                    ];
//
//
//                    OtherOrder::create($OtherOrder);
////                    dd($log['order_id']);
//                }
//            }
//        }
//        return $order;
return SafeService::expressCreate();


//        $res=AntchainPlusService::uploadPerformance('SANDBOX231011000000502901',2,97485,'123456');
//        return $res;
//        $res=AntchainPlusService::updatePromiseRepayment('SANDBOX231011000000504586',2);
//        return $res;
//        $res= AntchainPlusService::registerBclMerchant();
//        return $res;
//        $res= AntchainPlusService::queryOrder('PROD231017000000910005');
//        return $res;

    }
    public function exportNoPay(){


//       $res=MemberOther::whereIn('cert_no',["330683198612110013","320922199702122014","320922199702122014","411528199912182217","445281200005084357","371302199304070812","152324199506301111","152324199506301111","510922198402083691","510922198402083691","510922198402083691","410726200111130057","410726200111130057","352230198802170616","352230198802170616","352230198802170616","352230198802170616","0","500236199907232659","500236199907232659","370783199602153316","370783199602153316","370783199602153316","370783199602153316","321111199101221621","321111199101221621","321111199101221621","513001198702010218","513001198702010218","513001198702010218","340404199802040810","450328200110132411","450328200110132411","412829198904113229","350521198511118525","350521198511118525","350521198511118525","0","320830199811103618","320830199811103618","440823199911164614","440823199911164614","440823199911164614","420684199811225078","420684199811225078","420684199811225078","362228199902010526","362228199902010526","362228199902010526","362228199902010526","362228199902010526","362228199902010526","362228199902010526","362228199902010526","362228199902010526","362228199902010526","362228199902010526","362228199902010526","132801198903152214","132801198903152214","510802198602191717","342401199309272274","533422199101271510","342401199309272274","342401199309272274","220602199502030937","37292219890201521X","37292219890201521X","320106198805103221","320106198805103221","320106198805103221","320106198805103221","320106198805103221","37132619900710006X","37292219890201521X","220204198810110011","220204198810110011","220204198810110011","220204198810110011","220204198810110011","372928198812210212","372928198812210212","420703199805076392","420703199805076392","131121199911251416","131121199911251416","350583199011053116","350583199011053116","0","0","36078219920301381X","36078219920301381X","36078219920301381X","36078219920301381X","370725199712225276","433125199109010031","210202199209245927","210202199209245927","210202199209245927","0","441283200111304594","441283200111304594","441283200111304594","441283200111304594","422823199003264458","420204199806096511","210882199412263914","210882199412263914","210882199412263914","210882199412263914","210882199412263914","210882199412263914","230227198709012851","532325199207241515","422823199003264458","422823199003264458","422823199003264458","422823199003264458","422823199003264458","422823199003264458","339005198511010618","339005198511010618","339005198511010618","339005198511010618","339005198511010618","339005198511010618","339005198511010618","339005198511010618","339005198511010618","339005198511010618","339005198511010618","339005198511010618","130529198605010021","440823199502203619","440823199502203619","440823199502203619","440823199502203619","440823199502203619","440823199502203619","440823199502203619","330681199601057087","330681199601057087","330681199601057087","50010919950106251X","50010919950106251X","50010919950106251X","342425199805020528","340301199712090019","430124199709294745","430124199709294745","430124199709294745","430124199709294745","460033199502243883","460033199502243883","460033199502243883","232303198909251028","232303198909251028","232303198909251028","232303198909251028","232303198909251028","370303199010293936","370303199010293936","142723198912070215","330624199905115330","500102199406217996","513721199305080050","220322199810250949","220322199810250949","230123198506151113","230123198506151113","230123198506151113","370523199009231013","370523199009231013","370523199009231013","370523199009231013","320981199810130476","320981199810130476","341226198801043837","210623198401063495","210623198401063495","210623198401063495","340301199712090019","340301199712090019","610123199009277271","411503199611181029","411503199611181029","230604199211165123","331023200305143175","330183199510213019","330183199510213019","332523199209151127","332523199209151127","332523199209151127","332523199209151127","332523199209151127","332523199209151127","332523199209151127","332523199209151127","411282199803196515","510922199001014227","231182200101165622","522426199109273230","511621199310081042","430723199611287850","445122198912165091","412825199611036433","440508198704122943","230230199711182123","230230199711182123","331023200305143175","331023200305143175","331023200305143175","331023200305143175","131123200511260039","131123200511260039","131123200511260039","131123200511260039","131123200511260039","330227198201046376","612321199101240527","350524199902178019","130503199507270613","510183199502191618","23230219980806001X","510922199910161136","43052719931008662X","43052719931008662X","43052719931008662X","43052719931008662X","43052719931008662X","0","0","412724198904070057","410927200102284027","411503199611181029","411503199611181029","513901199801100028","232324198803055119","220103198610064530","320882199402031613","411327198810101138","411322199910280041","411322199910280041","411322199910280041","411322199910280041","411322199910280041","411322199910280041","411322199910280041","441381200108281814","230206199510190717","320882199212212659","321322200212103818","430581199604067289","430581199604067289","430581199604067289","230123199901222254","230123199901222254","230123199901222254","320281199002042277","372328198803140029","210682198601121063","210682198601121063","440681198702135428","441821198609280220","511622198704102274","410724199704243016","130322199008272014","130223199808314316","61242319980820101X","342523199505053742","610115199502115516","371426199811300017","371426199811300017","371426199811300017","230206199510190717","230206199510190717","230206199510190717","230206199510190717","420683199411162518","420683199411162518","340221199412202867","340221199412202867","340221199412202867","411323198206172612","411421200201206812","210521199707260033","210521199707260033","441821198609280220","441821198609280220","0","452622199708033316","131102199410180438","610422199911201415","350881199303100918","350881199303100918","410926199810080031","410926199810080031","410926199810080031","410926199810080031","220204199301310925","230622199303260868","230622199303260868","230622199303260868","230622199303260868","220204199301310925","220204199301310925","452231199710252010","430181199908140068","320923199606282428","51322719980814001X","320682198310306127","320682198310306127","320682198310306127","320682198310306127","320682198310306127","452623198309054234","452623198309054234","130481199605290478","130481199605290478","130481199605290478","320682199410028456","320682199410028456","411122199510157545","411122199510157545","411122199510157545","0","130821198701037975","130821198701037975","130821198701037975","411327198506190623","411327198506190623","411327198506190623","411327198506190623","511303199109213761","610329199807211217","220204198810110011","430703199001063256","430703199001063256","430703199001063256","430703199001063256","430703199001063256","430703199001063256","430703199001063256","430703199001063256","445102199304151920","445102199304151920","412702198804165050","412702198804165050","510781199710263559","510781199710263559","510781199710263559","340503199309190216","430421199007286035","430421199007286035","360622200107093227","360622200107093227","360622200107093227","360622200107093227","360622200107093227","360622200107093227","412724199104290355","412724199104290355","412724199104290355","412724199104290355","410403199201115524","450204198911201417","450204198911201417","640324200101053295","640324200101053295","640324200101053295","0","0","410702199703080018","340503199309190216","340503199309190216","440883198611083515","612323199610082910","110224198802253426","230321199411245937","230321199411245937","230321199411245937","320323199610110415","513223199807021435","410711198803211013","410711198803211013","370612199509061520","370612199509061520","152104199504143512","152104199504143512","429005200301300045","500102198712144778","500102198712144778","511381199505283779","511381199505283779","511381199505283779","511381199505283779","32012119940926251X","32012119940926251X","320283199105101367","320283199105101367","320283199105101367","131126199301111813","131126199301111813","131126199301111813","510602199504271514","230503198910140818","230503198910140818","433122198606042524","433122198606042524","130182199205174849","130182199205174849","130182199205174849","130182199205174849","42010419831228271X","42010419831228271X","42010419831228271X","310115199906042228","310115199906042228","310115199906042228","310115199906042228","310115199906042228","310115199906042228","210404199308204323","210404199308204323","210404199308204323","370686199406096514","370686199406096514","370686199406096514","370686199406096514","370686199406096514","0","320114199705152717","320114199705152717","370781199309094828","370781199309094828","370781199309094828","330781199510155920","330781199510155920","330781199510155920","52262219841111002X","0","500235199711080490","500235199711080490","511623199709175393","511623199709175393","110115199802152636","110115199802152636","110115199802152636","110115199802152636","32068419940518617X","32068419940518617X","32068419940518617X","612323199610082910","612323199610082910","612323199610082910","612323199610082910","32058619991113453X","32058619991113453X","612323199610082910","513029199708140065","513029199708140065","37148219950805001X","352203198912250087","362322199808160103","210102198202082213","413026199611166012","230105199606013422","370124199504233010","320981199402082217","320981199402082217","37148219950805001X","37148219950805001X","37148219950805001X","36011120000918652X","36011120000918652X","36011120000918652X","321023200012110810","321023200012110810","321023200012110810","532901198610250929","532901198610250929","210213199703170018","210213199703170018","210213199703170018","320323200203312015","320323200203312015","420582199304080080","330382198604090312","511025199112123443","511025199112123443","510902198508078326","152631198410052718","152631198410052718","152631198410052718","152631198410052718","152631198410052718","320323199308167920","511521199805087942","511521199805087942","511521199805087942","511521199805087942","511521199805087942","510106199003285115","510106199003285115","510106199003285115","612526199311138371","610422199509251772","610422199509251772","610422199509251772","610422199509251772","610422199509251772","21102119860705002X","21102119860705002X","330781199512025919","330781199512025919","330781199512025919","21028120000606641X","420621200008167710","420621200008167710","420621200008167710","532722199510310221","532722199510310221","532722199510310221","532722199510310221","0","440582199710292138","440582199710292138","130632199909087229","130632199909087229","130632199909087229","130632199909087229","130632199909087229","511623199607230021","370684198607257356","370684198607257356","511526199610125533","511526199610125533","511526199610125533","510503198511114054","510503198511114054","510503198511114054","510503198511114054","51052119971108343X","51052119971108343X","340825199907133718","0","0","0","210221199209156915","43098119920516821X","43098119920516821X","130281199607260722","142402198912156627","142402198912156627","142402198912156627","612525199403203656","371426200006284814","452702199602214573","452702199602214573","0","120113200101290010","120113200101290010","120113200101290010","220112200111261421","220112200111261421","130206199009050338","130206199009050338","130206199009050338","330483199304190051","532923198904200028","450225200010162213","140702199106267081","510602199504271514","510602199504271514","420525199403182819","321102198810031571","321102198810031571","321102198810031571","620103199808233028"])->where('cert_no','<>',0)->pluck('cert_no');
//        return $res;
//        $order = Order::from('sp_order_2 as o', 'o.id', 'ol.order_id')
//            ->leftjoin('sp_order_goods_2 as og', 'o.id', 'og.order_id')
//            ->leftjoin('sp_order_lease_2 as ol', 'o.id', 'ol.order_id')
//            ->leftjoin('sp_goods_2 as g','og.goods_id','g.id')
//            ->leftjoin('sp_member_2 as m', 'o.uid', 'm.id')
//            ->select(
//                'm.openId', 'ol.out_order_no','o.id','o.trade_no','o.location','o.status','ol.which_period',
//                'ol.paid_rent','o.remark', 'o.realname', 'o.mobile as address_mobile', 'o.address', 'o.order_from'
//                , 'og.goods_title',  'og.setmeal_title', 'og.is_buy_out', 'og.device_number', 'og.pact_type','og.setmeal_foregift','og.setmeal_price'
//                , 'm.mobile','m.cert_name','ol.pay_time',
//            )->where('ol.pay_time','>','1698768000')->where('ol.pay_time','<','1701360000')->where('o.seller_id','=','1685775283')->orderBy('pay_time','asc')->get()->toArray();
//
//        foreach ($order as $key=>$value) {
//            $dataInfo[$key][] = date('Y-m-d H:i:s',$value['pay_time']);
//            // 序号
//            $dataInfo[$key][] = $value['cert_name'];
//            // 日期
//            $dataInfo[$key][] =' '.$value['trade_no'].'/t';
//            // 用户名
//            $dataInfo[$key][] = $value['paid_rent'];
//        }
//
//        $headList = [
//            '还款时间',
//            '姓名',
//            '订单号',
//            '金额',
//        ];
//
//        $title = "小白十一月还款";
//
//        //调用上面的方法
//        return  csvExport($dataInfo, $headList, $title);
//        exit();

        $user= Order::from('sp_order_2 as o')
            ->where('o.status', '>','4')
            ->leftjoin('sp_order_goods_2 as og', 'o.id', 'og.order_id')
            ->leftjoin('sp_shop_user_2 as s', 'o.seller_id', 's.member_id')
            ->leftjoin('sp_member_2 as m', 'o.uid', 'm.id')
            ->distinct('m.id')
            ->select('m.mobile','m.cert_name','o.trade_no','o.month_total','s.shopname','o.is_lock',
                'og.acquisition_price','og.pact_type','og.setmeal_price','o.status','o.id','o.begin_time','o.reduced_price','m.contract_no','o.order_from','m.openId','o.sale_user_id')
            ->get()->toArray();

        foreach ($user as $key=>$value) {
            $dataInfo[$key][] = $value['begin_time'];
            // 序号
            $dataInfo[$key][] = $value['cert_name'];
            // 日期
            $dataInfo[$key][] =' '.$value['trade_no'].'/t';
            // 用户名
            $dataInfo[$key][] = $value['shopname'];
            $dataInfo[$key][] = OrderService::getOrderStatusName($value['status']);
            $dataInfo[$key][] = OrderLease::where('order_id',$value['id'])->sum('rent');
            $rent=OrderLease::where('order_id',$value['id'])->where('status',1)->sum('rent');
            $dataInfo[$key][] = bcadd($rent,$value['reduced_price'],2);
            $dataInfo[$key][] = $value['acquisition_price'];
            $dataInfo[$key][] = $value['month_total'];
            $dataInfo[$key][] = $value['is_lock']?'有':'无';

            $source = Source::where(['source_code' => $value['order_from'], 'status' => Source::SOURCE_STATUS_ENABLE])->value('source_name');
            $shopRate = OrderRate::where(['order_id' => $value['id']])->value('shop_rate');
            if($value['order_from']=='saleOnline'&&$value['openId']){
                $source=$source.'-微信';
            }
            if($value['order_from']=='saleOnline'&&empty($value['openId'])){
                $source=$source.'-支付宝';
            }
            if($value['contract_no']){
                $source=$source.'-W';
            }
            $shopRate = !empty($shopRate) ? "(" . $shopRate . "%)" : '';
            $source=$source . $shopRate;
            $channel_name=SaleUser::where('sale_user_id',$value['sale_user_id'])->value('channel_name');
            if($channel_name){
                $source=$source.'-'.$channel_name;
            }
            $dataInfo[$key][] = $source;
            if($value['pact_type']=='1'){
                $dataInfo[$key][] = $value['setmeal_price']>0?$value['setmeal_price']:0;
            }else{
                $dataInfo[$key][] = '无';
            }
        }


        $headList = [
            '租赁时间',
            '姓名',
            '订单号',
            '供应商',
            '状态',
            '应还',
            '已还款金额',
            '采购价格',
            '总期数',
            '是否有锁',
            '推广平台',
            '买断金',
        ];

        $title = "还款数据";

        //调用上面的方法
        return  csvExport($dataInfo, $headList, $title);
        exit();
    }

    /**
     * 推单推单
     * @param Request $request
     * @return mixed|void
     */
    public function pushOrder(Request $request)
    {

        $uids=Order::from('sp_order_2 as o')
            ->where('o.seller_id','202409107012090001')
            ->where('o.create_time','>','1726848000')
            ->leftjoin('sp_member_2 as u','o.uid','u.id')
            ->pluck('uid');
        $order= Order::from('sp_order_2 as o')
            ->leftjoin('sp_member_2 as m','m.id','o.uid')
            ->whereNotIn('o.uid',$uids)
            ->where('m.cert_no','<>','')
            ->where('m.cert_no','<>','0')
            ->where('m.cert_name','<>','')
            ->where('m.cert_name','<>','0')
            ->whereNull('o.sale_user_id')
            ->where('o.seller_id','1678175782')
            ->where('o.status',4)
            ->orderBy('o.id','desc')
            ->groupBy('o.uid')
            ->limit(10)
            ->select('o.uid','m.cert_name','m.mobile','o.id','o.trade_no')->get()->toArray();
        return $order;
        foreach ($order as $ra){
            $contextId = $ra['uid'];
            $log['order_id']=$ra['id'];
            if($log['order_id']){

                $otherorderData=OtherOrder::where('trade_no',$ra['trade_no'])->value('id');
                if($otherorderData){
                   continue;
                }
                $ordercount=Order::from('sp_order_2 as o')
                    ->where('o.uid',$contextId)
                    ->where('o.seller_id','202409107012090001')
                    ->where('o.status','<>',2)
                    ->leftjoin('sp_member_2 as u','o.uid','u.id')
                    ->count();

                $otherMember=OtherOrderAllocate::where('member_id','202409107012090001')->first();
                $otherMember = obToArray($otherMember);

                if(empty($otherMember)){
                    OtherOrderAllocate::where('timecate','>',0)->update(['timecate'=>0]);
                    $otherMember=OtherOrderAllocate::whereRaw('weight > timecate')->orderBy('id', 'desc')->first();
                    $otherMember = obToArray($otherMember);
                }


                if($ordercount<1){
                    if($otherMember){
                        OtherOrderAllocate::where('id',$otherMember['id'])->increment('timecate');
                        $isSendOther=$otherMember['member_id']?1:0;
                    }else{
                        return '';
                    }
                    $otherMember && OtherOrderAllocate::where('id',$otherMember['id'])->increment('totalcate');
                    $order_data= Order::from('sp_order_2 as o')->where('o.id',$log['order_id'])->leftjoin('sp_order_goods_2 as og','o.id','og.order_id')->first();
                    $order_lease_data=OrderLease::where('order_id',$log['order_id'])->get();
                    $order_lease_data=obToArray($order_lease_data);
                    $member = MemberOther::where('id',$contextId)->first();
                    $orderGoods=OrderGoods::where('order_id',$log['order_id'])->select('goods_id','setmeal_id')->first();
                    $goods = Goods::GoodsInfo($orderGoods['goods_id']);
                    $setmeal = GoodsSetmeal::getGoodsSetmealInfo($orderGoods['setmeal_id']);
                    $spec=GoodsSpec::GetSpecList($orderGoods['setmeal_id'],$orderGoods['goods_id']);
                    $order_goods_data['goods']  = $goods;
                    $order_goods_data['goods_setmeal']  = $setmeal;
                    $order_goods_data['goods_spec'] =$spec;


                    if($isSendOther){
                        $order_data['order_from']='alipay';
                        $add_remark = [
                            'uid'=>'23',
                            'username'=>'同步',
                            'create_time'=>time(),
                            'remark'=>'订单已推给其他平台'.$otherMember['name_tit'],
                            'order_id'=>$log['order_id']
                        ];
                        OrderRemark::insert($add_remark);
                        Order::where('id',$log['order_id'])->update(['username'=>'admin','seller_id'=>$otherMember['member_id']]);
                    }

                    $OtherOrder=[
                        'order_data'=>json_encode($order_data),
                        'trade_no'=>$order_data['trade_no'],
                        'order_lease_data'=>json_encode($order_lease_data),
                        'goods_data'=>json_encode($order_goods_data),
                        'member_data'=>json_encode($member->toArray()),
                        'remark_data'=>'[]',
                        'member_id'=>$otherMember['member_id'],
                        'order_id'=>$log['order_id'],
                        'status'=>1,
                        'from'=>1,
                        'is_allocate'=>1,
                    ];


                    OtherOrder::create($OtherOrder);
                    var_dump($order_data);
//                    dd($log['order_id']);
                }
            }
        }
    }

    //订单的导出
    public function exportOrders()
    {
            $user= Order::from('sp_order_2 as o')
            ->leftjoin('sp_member_2 as m', 'o.uid', 'm.id')
            ->leftjoin('sp_order_goods_2 as og', 'o.id', 'og.order_id')
            ->leftjoin('sp_shop_user_2 as s', 'o.seller_id', 's.member_id')
            ->whereNull('o.sale_user_id')
            ->orderBy('o.id','asc')
            ->where('o.create_time','>','1727280000')
            ->groupBy('o.uid')
            ->select('m.mobile','m.cert_name','s.mechanism','m.cert_no','o.trade_no','o.create_time','o.status',
                'o.id','o.rent_total','o.uid','o.sale_user_id','og.goods_title', 'og.imgurl','m.gender', 'og.setmeal_title','og.setmeal_price')
            ->get()->toArray();
        $user=obToArray($user);
        foreach ($user as $key=>$value) {
            $dataInfo[$key][] = date('Y-m-d',$value['create_time']);
            $dataInfo[$key][] = "\t".$value['cert_no'];
            $dataInfo[$key][] = $value['cert_name'];
            $dataInfo[$key][] = $value['mobile'];
            $dataInfo[$key][] =$value['goods_title'].$value['setmeal_title'];
            $dataInfo[$key][] =bcadd($value['rent_total'],$value['setmeal_price'],2);
            $dataInfo[$key][] = OrderService::getOrderStatusName($value['status']);
            $dataInfo[$key][] =$value['sale_user_id'];
        }
        $headList = [
            '创建时间',
            '身份证号码',
            '姓名',
            '电话',
            '商品名称',
            '订单金额',
            '状态',
            '渠道'
        ];
        $title = "用户订单";
        //调用上面的方法
        return  csvExporta($dataInfo, $headList, $title);

//        $user= Order::from('sp_order_2 as o')
//            ->leftjoin('sp_member_2 as m', 'o.uid', 'm.id')
//            ->leftjoin('sp_order_goods_2 as og', 'o.id', 'og.order_id')
//            ->leftjoin('sp_shop_user_2 as s', 'o.seller_id', 's.member_id')
//            ->where('o.sale_user_id','<>','')
//            ->orderBy('o.id','asc')
//            ->groupBy('o.uid')
//            ->select('m.mobile','m.cert_name','s.mechanism','m.cert_no','o.trade_no','o.create_time','o.status',
//                'o.id','o.rent_total','o.uid','o.sale_user_id','og.goods_title', 'og.imgurl','m.gender', 'og.setmeal_title','og.setmeal_price')
//            ->get()->toArray();
//        $user=obToArray($user);
//        foreach ($user as $key=>$value) {
//            $dataInfo[$key][] = date('Y-m-d H:i:s',$value['create_time']);
//            $dataInfo[$key][] = "\t".$value['cert_no'];
//            $dataInfo[$key][] = $value['cert_name'];
//            $dataInfo[$key][] = $value['mobile'];
//            $dataInfo[$key][] =$value['goods_title'].$value['setmeal_title'];
//            $dataInfo[$key][] =bcadd($value['rent_total'],$value['setmeal_price'],2);
//            $dataInfo[$key][] = OrderService::getOrderStatusName($value['status']);
//            if($value['sale_user_id']=='012418193027'){
//                $dataInfo[$key][] ='f1';
//            }else if($value['sale_user_id']=='012418205971'){
//                $dataInfo[$key][] ='f2';
//            }else if($value['sale_user_id']=='012610455071'){
//                $dataInfo[$key][] ='f3';
//            }else if($value['sale_user_id']=='012610463751'){
//                $dataInfo[$key][] ='f4';
//            }else if($value['sale_user_id']=='042419335455'){
//                $dataInfo[$key][] ='f5';
//            }
//        }
//        $headList = [
//            '创建时间',
//            '身份证号码',
//            '姓名',
//            '电话',
//            '商品名称',
//            '订单金额',
//            '状态',
//            '渠道'
//        ];
//        $title = "用户订单";
//        //调用上面的方法
//        return  csvExporta($dataInfo, $headList, $title);
//
//        $user= Order::from('sp_order_2 as o')
//            ->leftjoin('sp_member_2 as m','m.id','o.uid')
//            ->where('o.status',39)
//            ->whereIn('o.sale_user_id',['041818462836','042219205161'])
//            ->select('m.mobile','m.cert_name','m.cert_no','m.level_performance','o.id as order_id','o.id as orderId','o.uid','o.seller_id','o.status')
//            ->limit(100)
//            ->get();
//        $user=obToArray($user);
//        foreach ($user as $key=>$value) {
//            $dataInfo[$key][] = $value['cert_name'];
//            $dataInfo[$key][] = $value['mobile'];
//            $dataInfo[$key][] = "\t".$value['cert_no'];
//
//            $resa=OrderRadarBoolea::getRiskHistoryData($value['cert_no']);
//            $res=OrderRadarBoolea::getRiskData($value['cert_no']);
//            $radara=json_decode($resa['result'],true)['resp_data']['behavior_report_detail'];
//            $dataInfo[$key][] = "\t".$radara['B22170045'].'/'.$radara['B22170035'];//历史雷达近一个月
//            $radar=json_decode($res['result'],true)['resp_data']['behavior_report_detail'];
//            $dataInfo[$key][] = "\t".$radar['B22170045'].'/'.$radar['B22170035'];//雷达近一个月
//            $resa=OrderRiskBoolea::getRiskHistoryData($value['orderId']);
//            $res=OrderRiskBoolea::getRiskNewsData($value['orderId']);
//
//            $riska=json_decode($resa['result'],true)['resp_data']['personal_loan_h'];
//            $dataInfo[$key][] = "\t".$riska['repay_succ1'].'/'.$riska['repay_fail1'];//历史布尔近一个月
//
//            $risk=json_decode($res['result'],true)['resp_data']['personal_loan_h'];
//            $dataInfo[$key][] = "\t".$risk['repay_succ1'].'/'.$risk['repay_fail1'];//布尔近一个月
//
//            $dataInfo[$key][] = "\t".$radara['B22170046'].'/'.$radara['B22170036'];//历史雷达近一个月3
//            $dataInfo[$key][] = "\t".$radar['B22170046'].'/'.$radar['B22170036'];//雷达近一个月
//            $dataInfo[$key][] = "\t".$riska['repay_succ3'].'/'.$riska['repay_fail3'];//历史布尔近一个月
//            $dataInfo[$key][] = "\t".$risk['repay_succ3'].'/'.$risk['repay_fail3'];//布尔近一个月
//
//            $dataInfo[$key][] = "\t".$radara['B22170047'].'/'.$radara['B22170037'];//历史雷达近一个月6
//            $dataInfo[$key][] = "\t".$radar['B22170047'].'/'.$radar['B22170037'];//雷达近一个月
//            $dataInfo[$key][] = "\t".$riska['repay_succ6'].'/'.$riska['repay_fail6'];//历史布尔近一个月
//            $dataInfo[$key][] = "\t".$risk['repay_succ6'].'/'.$risk['repay_fail6'];//布尔近一个月
//
//
//            $dataInfo[$key][] = "\t".$radara['B22170048'].'/'.$radara['B22170038'];//历史雷达近一个月12
//            $dataInfo[$key][] = "\t".$radar['B22170048'].'/'.$radar['B22170038'];//雷达近一个月
//            $dataInfo[$key][] = "\t".$riska['repay_succ12'].'/'.$riska['repay_fail12'];//历史布尔近一个月
//            $dataInfo[$key][] = "\t".$risk['repay_succ12'].'/'.$risk['repay_fail12'];//布尔近一个月
//
//
//            $dataInfo[$key][] = "\t".$radara['B22170049'].'/'.$radara['B22170039'];//历史雷达近一个月24
//            $dataInfo[$key][] = "\t".$radar['B22170049'].'/'.$radar['B22170039'];//雷达近一个月
//            $dataInfo[$key][] = "\t".$riska['repay_succ24'].'/'.$riska['repay_fail24'];//历史布尔近一个月
//            $dataInfo[$key][] = "\t".$risk['repay_succ24'].'/'.$risk['repay_fail24'];//布尔近一个月
//
//
//        }
//        $headList = [
//            '姓名',
//            '电话',
//            '身份证',
//            '历史数据雷达近一个月',
//            '雷达近一个月',
//            '历史数据布尔近一个月',
//            '布尔近一个月',
//            '历史数据雷达近3个月',
//            '雷达近3个月',
//            '历史数据布尔近3个月',
//            '布尔近3个月',
//            '历史数据雷达近6个月',
//            '雷达近6个月',
//            '历史数据布尔近6个月',
//            '布尔近6个月',
//            '历史数据雷达近12个月',
//            '雷达近12个月',
//            '历史数据布尔近12个月',
//            '布尔近12个月',
//            '历史数据雷达近24个月',
//            '雷达近24个月',
//            '历史数据布尔近24个月',
//            '布尔近24个月',
//        ];
//        $title = "jj逾期用户还款比";
//        //调用上面的方法
//        return  csvExporta($dataInfo, $headList, $title);
//
//        $user= Order::from('sp_order_2 as o')
//           ->leftjoin('sp_member_2 as m', 'o.uid', 'm.id')
//           ->leftjoin('sp_order_goods_2 as og', 'o.id', 'og.order_id')
//           ->leftjoin('sp_shop_user_2 as s', 'o.seller_id', 's.member_id')
//            ->where('m.cert_no','<>','')
//            ->where('m.cert_no','<>','0')
//            ->groupBy('m.id')
//           ->whereIn('o.sale_user_id',['012418193027','012418205971','012610455071','012610463751','042419335455','070314212534'])
//           ->select('m.mobile','m.cert_name','s.mechanism','m.cert_no','o.trade_no','o.create_time',
//               'o.id','o.rent_total','o.uid','o.sale_user_id','og.goods_title', 'og.imgurl','m.gender', 'og.setmeal_title','og.setmeal_price')
//            ->orderBy('id','desc')
//           ->limit(1000)
//           ->get()->toArray();
//        $user=obToArray($user);
//        foreach ($user as $key=>$value) {
//            $dataInfo[$key][] = date('Y-m-d H:i:s',$value['create_time']);
//            $dataInfo[$key][] = "\t".$value['cert_no'];
//            $dataInfo[$key][] = $value['cert_name'];
//            $dataInfo[$key][] = $value['mobile'];
//            $dataInfo[$key][] =$value['goods_title'].$value['setmeal_title'];
//            $dataInfo[$key][] =bcadd($value['rent_total'],$value['setmeal_price'],2);
//            $dataInfo[$key][] =$value['sale_user_id']=='070314212534'?'bp':'fql';
//        }
//        $headList = [
//            '创建时间',
//            '身份证号码',
//            '姓名',
//            '电话',
//            '商品名称',
//            '订单金额',
//            '渠道'
//        ];
//        $title = "用户订单";
//        //调用上面的方法
//        return  csvExporta($dataInfo, $headList, $title);
////
//        //发送法诉短信
//        $res=parseFile('/www/wwwroot/www.doulaizu.com/public/cba.csv');
//        $i=0;$a=0;
//        foreach ($res as $key=>$data) {
//            if($key==0){
//                continue;
//            }
//           $user= Order::from('sp_order_2 as o')
//           ->leftjoin('sp_member_2 as m', 'o.uid', 'm.id')
//           ->leftjoin('sp_order_goods_2 as og', 'o.id', 'og.order_id')
//           ->leftjoin('sp_shop_user_2 as s', 'o.seller_id', 's.member_id')
//           ->where('o.trade_no','20230626160409770705')
//           ->select('m.mobile','m.cert_name','s.mechanism','m.cert_no','o.trade_no','o.id','s.member_id','o.uid','o.seller_id','og.goods_title', 'og.imgurl','m.gender', 'og.setmeal_title')
//           ->first()->toArray();
//           $sexint = (int) substr($user['cert_no'], 16, 1);
//           $gender= $sexint % 2 === 0 ? '女士' : '先生';
//
//           $data = array();
//           $data['content'] = '[债权转让通知]'.$user['cert_name'].$gender.':您通过【都来租物】申请的 '.$user['goods_title'].$user['setmeal_title'].'手机租赁业务，
//           订单编号:【'.$user['trade_no'].'】2024年9月14日'.$user['mechanism'].'与崇信云盛科企业管理服务有限公司达成的债权转让协议，现将我公司对您的所有债权，依法转让给崇信云盛科企业管理服务有限公司，此转让债权相关的其他权利也一并转让，请您自接到该债权转让通知书后【3】日内向崇信云盛科企业管理服务有限公司履行全部义务。专此通知。';
//           // dd( $data['content']);
//           $send_res=SmsService::send_msg($user['mobile'],$data['content']);
//           var_dump($user['trade_no']);
//           var_dump($send_res);
//           if($send_res['status']){
//               $send_status = 1;
//               $reason = 'OK';
//           }else{
//               $send_status = 2;
//               $reason = $send_res['msg'];
//           }
//
//           $data['order_id'] = $user['trade_no'];
//           $data['mobile'] = $user['mobile'];
//           $data['member_id'] =$user['member_id'];
//           $data['template_id'] ='26';
//           $data['reason'] = $reason;
//           $data['send_user'] = $user['uid'];
//           $data['send_status'] = $send_status;
//           $data['create_time'] = date('Y-m-d H:i:s');
//           SmsRecord::insert($data);
//        }



//        exit();
//        return;
//        //上传拿货价
//       $res=parseFile('/www/wwwroot/www.doulaizu.com/public/cba.csv');
//       $i=0;$a=0;
//           foreach ($res as $data) {
//           $orderId=Order::where('trade_no',$data[0])->where('seller_id','<>',1704471788)->value('id');
////               var_dump($data);
////           dd($orderId);
//               if($orderId&&$data['2']){
//              $res=OrderGoods::where('order_id',$orderId)->update(['acquisition_price'=>$data['2'],'device_number'=>$data['1']]);
////                   if($res!==false){
//                       var_dump($a++.'--'.$res);
//                       var_dump($i+=$data['2']);
////                   }
//                }else{
//                   var_dump($data[0]);
//               }
//            }
//           exit();
//       return ;
//        $user= Order::from('sp_order_2 as o')
//            ->leftjoin('sp_member_2 as m','m.id','o.uid')
//            ->whereIn('o.status',['30'])
//            ->select('m.mobile','m.cert_name','m.cert_no','o.trade_no','o.id as order_id','o.uid','o.seller_id','o.status','o.create_time')
//            ->orderBy('o.id','desc')
//            ->get();
//        $user=obToArray($user);
//        foreach ($user as $key=>$value) {
//            $dataInfo[$key][] = "\t".$value['cert_no'];
//            $dataInfo[$key][] = OrderService::getOrderStatusName($value['status']);
//            $dataInfo[$key][] = date('Y-m-d H:i:s',$value['create_time']);
//            $dataInfo[$key][] = "\t".$value['trade_no'];
//        }
//        $headList = [
//            '身份证',
//            '订单状态',
//            '订单时间',
//            '订单号',
//        ];
//        $title = "订单数据";
//        //调用上面的方法
//        return  csvExporta($dataInfo, $headList, $title);

//        $user= Order::from('sp_order_2 as o')
//            ->leftjoin('sp_member_2 as m','m.id','o.uid')
//            ->where('m.level_performance','<>','')
//            ->where('m.level_performance','<>','0')
//            ->whereIn('o.sale_user_id',['041818462836','042219205161'])
//            ->select('m.mobile','m.cert_name','m.cert_no','m.level_performance','o.id as order_id','o.uid','o.seller_id','o.status')
//            ->get();
//        $user=obToArray($user);
//        foreach ($user as $key=>$value) {
//            $dataInfo[$key][] = $value['cert_name'];
//            $dataInfo[$key][] = $value['mobile'];
//            $dataInfo[$key][] = OrderService::getOrderStatusName($value['status']);
//            $dataInfo[$key][] = $value['level_performance'];
//        }
//        $user= Order::from('sp_order_2 as o')
//            ->leftjoin('sp_member_2 as m', 'o.uid', 'm.id')
//            ->leftjoin('sp_order_goods_2 as og', 'o.id', 'og.order_id')
//            ->leftjoin('sp_shop_user_2 as s', 'o.seller_id', 's.member_id')
//            ->where('m.cert_no','<>','')
//            ->where('m.cert_no','<>','0')
//            ->where('m.level_performance','<>','')
//            ->where('m.level_performance','<>','0')
//            ->whereIn('o.sale_user_id',['041818462836','042219205161'])
//            ->groupBy('m.id')
//            ->select('m.mobile','m.cert_name','s.mechanism','m.cert_no','o.trade_no','m.level_performance','o.create_time','o.status',
//                'o.id','o.rent_total','o.uid','o.sale_user_id','og.goods_title', 'og.imgurl','m.gender', 'og.setmeal_title','og.setmeal_price')
//            ->orderBy('id','desc')
//            ->limit(1000)
//            ->get()->toArray();
//        $user=obToArray($user);
//        foreach ($user as $key=>$value) {
//            $dataInfo[$key][] = date('Y-m-d H:i:s',$value['create_time']);
//            $dataInfo[$key][] = "\t".$value['cert_no'];
//            $dataInfo[$key][] = $value['cert_name'];
//            $dataInfo[$key][] = $value['mobile'];
//            $dataInfo[$key][] =$value['goods_title'].$value['setmeal_title'];
//            $dataInfo[$key][] =bcadd($value['rent_total'],$value['setmeal_price'],2);
//            $dataInfo[$key][] = OrderService::getOrderStatusName($value['status']);
//            $dataInfo[$key][] = $value['level_performance'];
//        }
//        $headList = [
//            '创建时间',
//            '身份证号码',
//            '姓名',
//            '电话',
//            '套餐信息',
//            '订单金额',
//            '订单状态',
//            '履约等级',
//        ];
//        $title = "jj1-2用户的履约等级";
//        //调用上面的方法
//        return  csvExporta($dataInfo, $headList, $title);

      $order = Order::from('sp_order_2 as o', 'o.id', 'ol.order_id')
//           ->leftjoin('sp_order_lease_2 as ol', 'o.id', 'ol.order_id')
           ->leftjoin('sp_member_2 as m', 'o.uid', 'm.id')

          ->where('o.seller_id','1704471788')
//           ->where('o.area','like','%宜都市%')
          ->leftjoin('sp_shop_user_2 as s', 'o.seller_id', 's.member_id')
          ->select(
               'm.openId','o.id','o.trade_no','o.location','o.status','s.shopname',
               'o.is_insurance_choose_custom','o.remark', 'o.realname', 'o.mobile as address_mobile', 'o.address', 'o.order_from',
               'm.mobile','m.cert_name',
           )->whereIn('o.status',['30','38','39'])->orderBy('id','asc')->groupBy('o.trade_no')->get()->toArray();

       foreach ($order as $key=>$value) {
           $dataInfo[$key][] = $value['shopname'];
           $dataInfo[$key][] = "\t".$value['trade_no'];
           $dataInfo[$key][] = $value['cert_name'];
           $dataInfo[$key][] = "\t".$value['mobile'];
           $dataInfo[$key][] = OrderService::getOrderStatusName($value['status']);
           $orderLease =OrderLease::where('order_id',$value['id'])->where('overdue_days','>=',1)->orderBy('id','asc')->select('begin_time','id')->first();
           $dataInfo[$key][] = $orderLease?date('Y-m-d',$orderLease['begin_time']):'';
           $dataInfo[$key][] = OrderLease::where('id',$orderLease['id'])->value('rent');
           $begin_time =OrderLease::where('id',$orderLease['id'])->where('status',1)->orderBy('id','desc')->value('pay_time');
           $dataInfo[$key][] = $begin_time?date('Y-m-d',$begin_time):'';
           $dataInfo[$key][] = OrderLease::where('id',$orderLease['id'])->value('paid_rent');
       }
       $headList = [
           '商家名称',
           '订单编号',
           '姓名',
           '手机号码',
           '订单状态',
           '首次逾期时间',
           '逾期金额',
           '最新还款的时间',
           '还款金额',
       ];

       $title = "逾期订单";

       //调用上面的方法
       return  csvExporta($dataInfo, $headList, $title);

    }

    public function testAto(Request $request){

// AntchainAtoService::cancelWithholdPlan('20240925174324383385');
//
//return  AntchainAtoService::closeOrder('20240925174324383385');

//  return AntchainAtoService::asyncUnbindConfirm('20240920144508615299', "AGREE", null, 0, null);
//return AntchainAtoService::createWithholdRefund('20240506115812395367',1,'106658');
//return  AntchainAtoService::queryWithholdRefund('20240506115812395367',1);
//     return  AntchainAtoService::repayWithholdPlan('20240622114748403579',3,'999.83');
//     return AntchainAtoService::queryWithholdSign('20240926191229941820');
//
       return AntchainAtoService::getTradeUserperformance('20240506115812395367');
//        return  AntchainAtoService::retryWithholdPlan('20240618200557321853',2);
//        return  AntchainAtoService::queryOrderFulfillment('20240617175332800234');
//        return  AntchainAtoService::getTradeUserperformance('20240722163849720042');
//         return  AntchainAtoService::queryOrder('20240920144508615299');
//  return  AntchainAtoService::repayWithholdPlan('20240720135617738195',2,'1916.47');
//  return AntchainAtoService::createWithholdRefund('20240720135617738195',2,191647);
//  return  AntchainAtoService::queryWithholdRefund('20240720135617738195',2);

    }

   public function useTest(Request $request){



//       $res = AntchainService::templateCreate();//上传合同模板af9c2a002d7a4b83bd6a516e42197017
//       dd($res);
//       $res=EsignService::createByUploadUrl();
//      dd($res);
//       $where[] =['m.openId', '<>',''];
//       $where[] =['ol.out_order_no', '<>',''];
//       $orderList = Order::from('sp_order_2 as o')
//           ->leftjoin('sp_order_goods_2 as og', 'o.id', 'og.order_id')
//           ->leftjoin('sp_order_lease_2 as ol', 'o.id', 'ol.order_id')
//           ->leftjoin('sp_shop_user_2 as s', 'o.seller_id', 's.member_id')
//           ->leftjoin('sp_order_return_2 as or', 'o.id', 'or.order_id')
//           ->leftjoin('sp_goods_2 as g','og.goods_id','g.id')
//           ->leftjoin('sp_member_2 as m', 'o.uid', 'm.id')
//           ->select(
//               'm.openId', 'ol.out_order_no','o.id','o.trade_no','o.location','o.status','or.logistics_no','or.create_time',
//               'o.is_insurance_choose_custom','o.remark', 'o.realname', 'o.mobile as address_mobile', 'o.address', 'o.sign_status', 'o.guarantee_status', 'o.pact_url', 'o.is_skip', 'o.order_from'
//               , 'og.goods_title', 'og.imgurl', 'og.setmeal_title', 'og.is_buy_out', 'og.device_number', 'og.pact_type','og.setmeal_foregift','og.setmeal_price'
//               , 'm.mobile',
//           )
//           ->whereIn('o.status',['30','20','38','39'])
//           ->where($where)->orderBy('id','asc')->get();
//       $orderList=obToArray($orderList);
////        dd($orderList);
//       foreach ($orderList as $ra){
//           WechatService::upload_shipping_info($ra);
//       }
//       return $orderList;
       //天创法诉查询
//       $array['cert_name']='许成楠';
//       $array['cert_no']='330183199506063214';
//       $array['mobile']='13456700054';
//       $array['id']='';
//       $res=YpcreditService::query($array);

//       dd($res);
       //创建商户
       $res= AntchainPlusService::registerBclMerchant();
       var_dump(obToArray($res));
       dd($res);
//       $res=SmsService::voiceMarketing('19357616167','2023-09-21 18:00:00|1000');
//       dd($res);






       //
       //$res=SmsService::sendCode(17779146889);
//       $a=explode(',','15128,5646,5647,5648,5649,5651,5652,5653,5654,5655,5657,5705,5706,5710,5712,5718,5719,5720,5721,5722,5723,5724,5725,5782,5783,5784,5788,5789,5790,5791,5792,5917,5918,5919,5920,5921,5922,5923,5924,5925,5926,5918,5919,5920,5921,5922,5923,5924,5925,5926,5927,5955,5956,5957,5962,5964,5966,5972,5974,5975,5977,22177,22182,22183,22184,22185,22188,22191,22192,22195,22197,22177,22182,22183,22184,22185,22188,22191,22192,22195,22197,22177,22182,22183,22184,22185,22188,22191,22192,22195,22197,21863,21867,21868,21869,21871,21872,21874,21875,21879,21881,22012,22015,22058,22072,22073,22075,22084,22085,22087,22088,22223,22224,22225,22226,22227,22229,22231,22232,22238,22241,22225,22226,22227,22229,22231,22232,22233,22238,22241,22242,22242,22243,22244,22245,22246,22247,22248,22249,22250,22251,5705,5706,5710,5712,5718,5719,5720,5721,5722,5723,5724,5725,5782,5783,5784,5788,5789,5790,5791,5792,5917,5918,5919,5920,5921,5922,5923,5924,5925,5926,5918,5919,5920,5921,5922,5923,5924,5925,5926,5927,5955,5956,5957,5962,5964,5966,5972,5974,5975,5977,22177,22182,22183,22184,22185,22188,22191,22192,22195,22197,22177,22182,22183,22184,22185,22188,22191,22192,22195,22197,22177,22182,22183,22184,22185,22188,22191,22192,22195,22197,21863,21867,21868,21869,21871,21872,21874,21875,21879,21881,22012,22015,22058,22072,22073,22075,22084,22085,22087,22088,22223,22224,22225,22226,22227,22229,22231,22232,22238,22241,22225,22226,22227,22229,22231,22232,22233,22238,22241,22242,22242,22243,22244,22245,22246,22247,22248,22249,22250,22251,5927,5955,5956,5957,5962,5964,5966,5972,5974,5975,5977,22177,22182,22183,22184,22185,22188,22191,22192,22195,22197,22177,22182,22183,22184,22185,22188,22191,22192,22195,22197,22177,22182,22183,22184,22185,22188,22191,22192,22195,22197,21863,21867,21868,21869,21871,21872,21874,21875,21879,21881,22012,22015,22058,22072,22073,22075,22084,22085,22087,22088,22223,22224,22225,22226,22227,22229,22231,22232,22238,22241,22225,22226,22227,22229,22231,22232,22233,22238,22241,22242,22242,22243,22244,22245,22246,22247,22248,22249,22250,22251,22012,22015,22058,22072,22073,22075,22084,22085,22087,22088,22223,22224,22225,22226,22227,22229,22231,22232,22238,22241,22225,22226,22227,22229,22231,22232,22233,22238,22241,22242,22242,22243,22244,22245,22246,22247,22248,22249,22250,22251,22069');
//       $res= Order::where('seller_id',1677219996)
//           ->where('status',OrderService::ORDER_STATUS_SIGN_NOCHECK)
//           ->where('create_time','<',time()-86400*7)
////           ->select('id')
////           ->get()->toArray();
//           ->update(['status' => OrderService::ORDER_STATUS_CENCEL,'update_time'=>time()]);
//       return $res;

//       $sql= Order::where('status',OrderService::ORDER_STATUS_SIGN_NOCHECK)
//           ->whereBetween('create_time',[1690260941,1690282557])
//           ->select('id','uid','create_time', DB::raw('count(create_time) as created_at'))
//           ->having('created_at', '>', 1)
//           ->groupByRaw('uid,create_time')->get()->toArray();
//       foreach ($sql as $ra){
//           $res=Order::where('status',OrderService::ORDER_STATUS_SIGN_NOCHECK)->where('id',$ra['id'])->update(['status'=>OrderService::ORDER_STATUS_CENCEL]);
////         var_dump($res);break;
//       }
//       var_dump($sql);exit;
       //e签宝 通过上传方式创建模板
//       dd(66);
//  $res=OrderService::createThree([]);
//       $res=SmsService::sendCode(15994098637);
//       $orderId=5;
//       $certName='';
//       $certNo='a1aac87579b565c158e299396e16636c';
//       $mobile='fc490d20adee9000dfc31db3d19b6191';
//       $member_id=1660615608;
//    $res=RiskCredit::queryRiskCredit($orderId,$certName,$certNo,$mobile,$member_id);
//       $mobile='';
//       $code=123456;
//       $message = '您好，您的账户余额不足，担保合同充值失败，请尽快完成充值';
// $res=EsignService::createByUploadUrl();
// dd($res);
//       $res=AliyunSmsService::main('phone');
//       dd($res);
//       $res=ShopSms::orderRefundSuccess('1662369172','阿杰','20220907104014275167','手机号','3','1');
//       $fileName = "2ef168a1272f460fb076d08722cbe3f3_20230807152901.pdf";
//       $file = file_get_contents(dirname(dirname(dirname(dirname(dirname(__FILE__))))) . '/storage/tmp/'.$fileName);
//       $path = dirname(dirname(dirname(dirname(dirname(__FILE__))))) . '/storage/tmp/'.$fileName;
//       $fileName="2ef168a1272f460fb076d08722cbe3f4.pdf";
//       file_put_contents($path,$file);
//       $uploud_res = AlipayService::upload($fileName,$path);
//      dd($uploud_res);
//       if($uploud_res['status']){
//           if(file_exists($path)){
//               unlink($path);
//           }
//       }
//      dd($path);
//       $res= AntchainService::download('789fb10ec56647c4a4b214fbb1bcdf78');
//       return $res;
//       $res=EsignService::downloadDocument('434d9705720f4eac911704b751ec3a9b');
//       return $res;
//       $order= Order::from('sp_order_2 as o')->where('o.id','28312')
//           ->leftjoin('sp_shop_user_2 as u','u.member_id','o.seller_id')
//           ->leftjoin('sp_order_goods_2 as og','o.id','og.order_id')
//           ->leftjoin('sp_member_2 as m','m.id','o.uid')
//           ->leftjoin('sp_order_return_2 as or','o.id','or.order_id')
//           ->select(
//               'o.id','o.uid','o.status','o.rent_total','o.month_total','o.foregift','o.seller_id','o.trade_no','o.realname','o.mobile as user_mobile','o.flow_id','o.amount','o.other_order_id','o.other_user_id','o.form_id','o.create_time','o.payer_user_id','o.begin_time','o.end_time','o.pay_type','o.order_from','o.is_skip','o.financing_type','o.is_renewal','o.parent_order_no','o.pact_url_2','o.pact_url_3'
//               ,'og.goods_title','og.lease_price','og.lease_set','og.goods_id','og.setmeal_id','og.spec_id','og.lease_time','og.start_date','og.imgurl','og.setmeal_foregift'
//               ,'m.cert_no','m.user_id','m.cert_name','m.cert_no','m.mobile','m.esign_user_id','m.esign_seal_id'
//               ,'u.shopname','or.logistics_no','u.is_guarantee','u.guarantee_amount','u.guarantee_minage','u.guarantee_maxage','u.mechanism'
//           )
//           ->first();
//       $order = $order ? $order->toArray() : [];
//       $order['rent_pay']=OrderLease::where('order_id',$order['id'])->orderBy('id','asc')->value('rent');
//       AlipayMessageService::sendChangeOrderMessage($order);
   }
   public function closeCopyOrder(){
      $sql= Order::whereBetween('create_time',[1689264000,1689334970])
           ->select('id', DB::raw('count(create_time) as created_at'))
           ->having('create_time', '>', 100)
           ->groupBy('uid')->get();
      var_dump($sql);
   }
   //线下支付 线上同步预授权订单
    public function payOffLine(){
        /*
        COMPLETE：同步用户已履约
        适用场景：发起扣款后，芝麻生成待履约记录，如果用户通过其他方式完成订单支付，请反馈该状态，芝麻将完结待履约记录对用户形成一条良好履约记录；

        CLOSED： 同步履约已取消
        适用场景：发起扣款后，芝麻生成待履约记录，如果发现该笔扣款无效需要取消，请反馈该状态，芝麻将取消用户待履约记录；

        VIOLATED： 用户已违约
        适用场景：如果用户在约定时间（具体根据行业约定，有一定宽限期）内未完成订单支付，反馈该状态，芝麻将对用户记录一条负面记录，请谨慎使用；

        sp_other_withhold_log表  使用order_no搜索
        */
        $orderData = [
            'orderId'    => '20221117130359667037', //order_no
            'outTradeNo' => '20221117130359667037|6551', //out_trade_no
            'tradeNo'    => '2022111722001400851425108003', //trade_no
            'status'     => 'COMPLETE',
        ];
        $res = AlipayService::orderInfo(10001, $orderData);

        dd($res);



    }
    //智能合同
    public function tests_templateCreate(Request $request){

    }


 public function exportOrder(){
        $ressult=Db::table('sp_other_order_2')->whereDate('created_at','2023-9-18')->where('is_allocate',1)->limit(100)->orderBy('created_at','desc')->get();
     $ressult=obToArray($ressult);
//        dd($res);
        // dd(COUNT($res['data']));
     $i=0;
        if($ressult){ //成功
            foreach($ressult as $data){
                //请求订单数量
                $order_count = COUNT($res['data']);
                $order_data = json_decode($data['order_data'],true);

                $res=Db::table('sp_other_order_2')->where('id',$data['id'])->decrement('is_allocate');

//                if(Redis::get('TradeNo'.$order_data['trade_no'])){
//                    continue;
//                }
                var_dump('begin'.$data['id']);
                if(Order::where('trade_no',$order_data['trade_no'])->value('id')){
                    continue;
                }

                $otherMember=OtherOrderAllocate::whereRaw('weight > timecate')->orderBy('id', 'desc')->select('member_id','limit','id')->first();
                $otherMember = obToArray($otherMember);

var_dump('allow'.$data['id']);

                if(empty($otherMember)){
                    OtherOrderAllocate::where('timecate','>',0)->update(['timecate'=>0]);
                    $otherMember=OtherOrderAllocate::whereRaw('weight > timecate')->orderBy('id', 'desc')->select('member_id','id')->first();
                    $otherMember = obToArray($otherMember);
                }
                if($order_data&&$otherMember){
                    if($otherMember['limit']){
                        $order_limit_count=OtherOrder::where('member_id',$otherMember['member_id'])->whereDate('created_at', date('Y-m-d'))->count();
                        if($order_limit_count>=$otherMember['limit']){
                            $otherMember=OtherOrderAllocate::whereRaw('limit = 0')->first();
                        }
                    }
                    $OtherOrder=[
                        'order_data'=>$data['order_data'],
                        'order_lease_data'=>$data['order_lease_data'],
                        'goods_data'=>$data['goods_data'],
                        'member_data'=>$data['member_data'],
                        'remark_data'=>$data['remark_data'],
                        'member_id'=>$otherMember['member_id'],
                        'order_id'=>$order_data['id'],
                        'status'=>1,
                        'is_allocate'=>1
                    ];
                    OtherOrder::create($OtherOrder);
                    OtherOrderAllocate::where('id',$otherMember['id'])->increment('timecate');
                    $isSendOther=$otherMember['member_id']?1:0;
                }
//                dd($isSendOther);
                $otherMember && OtherOrderAllocate::where('id',$otherMember['id'])->increment('totalcate');

                $order_lease_datas = json_decode($data['order_lease_data'],true);
                $goods_data = json_decode($data['goods_data'],true);
                $member_data = json_decode($data['member_data'],true);
                $remark_data = json_decode($data['remark_data'],true);
                // dd($order_lease_datas);

                // if(!empty($order_data) && !empty($order_lease_datas) && !empty($goods_data) && !empty($member_data)){
                if(!empty($order_data) && !empty($goods_data) && !empty($member_data)){
                    $this->upload_img($order_data['imgurl']);
                    $this->upload_img($member_data['idcard_front']);
                    $this->upload_img($member_data['idcard_back']);

//                dd($order_lease_datas);
                    //会员资料
                    $cert_no = $member_data['cert_no'];
                    $member = MemberOther::where('cert_no',$cert_no)->select('id')->first();
                    $member = obToArray($member);
                    if($member){
                        $uid = $member['id'];
                    }else{

                        $add_member_data = [
                            'mobile'=>$member_data['mobile'],
                            'user_id'=>isset($member_data['user_id'])?$member_data['user_id']:0,
                            'cert_name'=>$member_data['cert_name'],
                            'cert_no'=>$cert_no,
                            'idcard_front'=>$member_data['idcard_front'],
                            'idcard_back'=>$member_data['idcard_back'],
                            'head_image'=>$member_data['head_image'],
                            'nick_name'=>$member_data['nick_name'],
                            'gender'=>$member_data['gender'],
                            'province'=>$member_data['province'],
                            'city'=>$member_data['city'],
                            'status'=>'1',
                            'create_time'=>time(),
                            'update_time'=>time()
                        ];
                        //ceshi123
                        $uid = MemberOther::insertGetId($add_member_data);//会员ID
                    }
                    $goods_detail = $goods_data['goods'];
                    // dd($goods_detail);
                    $goods_setmeal_detail = $goods_data['goods_setmeal'];
                    $goods_spec_details = $goods_data['goods_spec'];

                    // $goods_title = $goods_detail['title'];
                    // $goods = Goods::where('title',$goods_title)->select('id')->first();
                    // $goods = obToArray($goods);
                    // if($goods){
                    //     $goods_id = $goods['id'];
                    // }else{
                    //商品
                    $add_goods_data = [
                        'title'=>$goods_detail['title'],
                        'new_grade'=>$goods_detail['new_grade'],
                        'member_id'=>'1687342445',
                        'category_id'=>'0',
                        'status'=>'2',
                        'pay_type'=>'1',
                        'ischeck'=>'4',
                        'is_delete'=>'1',
                        'create_time'=>time(),
                        'update_time'=>time(),
                        'is_show'=>'2'
                    ];
                    //ceshi123
                    $goods_id = Goods::insertGetId($add_goods_data);//商品ID
                    // }
                    //商品套餐
                    $add_goods_setmeal_data = [
                        'goods_id'=>$goods_id,
                        'title'=>$goods_setmeal_detail['title'],
                        'quantity'=>$goods_setmeal_detail['quantity'],
                        'foregift'=>$goods_setmeal_detail['foregift'],
                        'price'=>$goods_setmeal_detail['price'],
                        'create_time'=>time()
                    ];
                    //ceshi123
                    $setmeal_id = GoodsSetmeal::insertGetId($add_goods_setmeal_data);//商品套餐ID
                    //商品套餐详情
                    foreach($goods_spec_details as $goods_spec_detail){
                        $add_goods_spec_data = [
                            'lease_time'=>$goods_spec_detail['lease_time'],
                            'setmeal_id'=>$setmeal_id,
                            'lease_price'=>$goods_spec_detail['lease_price'],
                            'withhold_cycle'=>$goods_spec_detail['withhold_cycle'],
                            'day_price'=>$goods_spec_detail['day_price'],
                            'goods_id'=>$goods_id
                        ];

                        //ceshi123
                        $spec_id = GoodsSpec::insert($add_goods_spec_data);//商品套餐ID
                    }
//                $spec_id=1;
                    //订单
                    $add_order_data = [
                        'seller_id'=>'1687342445',
                        'username'=>$isSendOther?'admin':'tingxiangzu',
                        'uid'=>$uid,
                        'trade_no'=>$order_data['trade_no'],
                        'is_insurance_choose'=>$order_data['is_insurance_choose'],
                        'rent_total'=>$order_data['rent_total'],
                        'month_total'=>$order_data['month_total'],
                        'amount'=>$order_data['amount'],
                        'payment'=>$order_data['payment'],
                        'remark'=>$order_data['remark'],
                        'realname'=>$order_data['realname'],
                        'mobile'=>$order_data['mobile'],
                        'address'=>$order_data['address'],
                        'pay_time'=>$order_data['pay_time'],
                        'prov'=>$order_data['prov'],
                        'city'=>$order_data['city'],
                        'area'=>$order_data['area'],
                        'begin_time'=>$order_data['begin_time'],
                        'end_time'=>$order_data['end_time'],
                        'payer_user_id'=>$order_data['payer_user_id'],
                        'user_email'=>$order_data['user_email'],
                        'old_order_id'=>$order_data['id'],
                        'status'=>OrderService::ORDER_STATUS_SIGN_NOCHECK,
                        'create_time'=>time(),
                        'update_time'=>time(),
                        'pay_type'=>'1',
                        'order_from'=>'tingxiangzu-'.$order_data['order_from'],
                        'foregift_deduct'=>$order_data['foregift_deduct'],
                        'foregift_pay'=>$order_data['foregift_pay']
                    ];
                    //ceshi123
                    $order_id = Order::insertGetId($add_order_data);//订单ID
                   // var_dump($order_id);
//                dd($order_id);
                    //ceshi123
                    $res_set = RadarService::setOtherOrder($order_count,$order_data['id']);
                    //风控备注
                    if($remark_data){
                        foreach($remark_data as $remark_value){
                            $add_remark_data = [
                                'uid'=>'23',
                                'username'=>'同步',
                                'create_time'=>time(),
                                'remark'=>$remark_value['remark'].'(风控建议)',
                                'order_id'=>$order_id
                            ];
                            OrderRemark::insert($add_remark_data);
                        }
                    }

                    $add_remark = [
                        'uid'=>'23',
                        'username'=>'同步',
                        'create_time'=>time(),
                        'remark'=>'同步订单',
                        'order_id'=>$order_id
                    ];
                    OrderRemark::insert($add_remark);

                    if($isSendOther==1){
                        $add_remark = [
                            'uid'=>'23',
                            'username'=>'同步',
                            'create_time'=>time(),
                            'remark'=>'订单已推给其他平台',
                            'order_id'=>$order_id
                        ];
                        OrderRemark::insert($add_remark);
                    }
                    //订单商品
                    $add_order_goods_data = [
                        'order_id'=>$order_id,
                        'goods_id'=>$goods_id,
                        'goods_title'=>$order_data['goods_title'],
                        'imgurl'=>$order_data['imgurl'],
                        'setmeal_id'=>$setmeal_id,
                        'setmeal_title'=>$order_data['setmeal_title'],
                        'spec_id'=>$spec_id,
                        'lease_set'=>$order_data['lease_set'],
                        'lease_time'=>$order_data['lease_time'],
                        'lease_price'=>$order_data['lease_price'],
                        'setmeal_price'=>$order_data['setmeal_price'],
                        'setmeal_foregift'=>$order_data['setmeal_foregift'],
                        'start_date'=>$order_data['start_date'],
                        'pact_type'=>$order_data['pact_type'],
                        'is_buy_out'=>$order_data['is_buy_out'],
                        'create_time'=>$order_data['create_time'],
                        'device_number'=>$order_data['device_number'],
                        'website_price'=>$order_data['website_price'],
                        'seller_id'=>'1687342445'
                    ];
                    //ceshi123
                    OrderGoods::insert($add_order_goods_data);

                    //订单租期
                    foreach($order_lease_datas as $order_lease_data){
                        $add_order_lease_data = [
                            'order_id'=>$order_id,
                            'which_period'=>$order_lease_data['which_period'],
                            'rent'=>$order_lease_data['rent'],
                            'begin_time'=>$order_lease_data['begin_time'],
                            'end_time'=>$order_lease_data['end_time'],
                            'create_time'=>$order_lease_data['create_time']
                        ];
                        //ceshi123
                        OrderLease::insert($add_order_lease_data);
                    }

                    $authenticLog = AuthenticLog::where('order_id',$order_id)->select('id')->first();
                    $authenticLog = obToArray($authenticLog);
                    if($authenticLog){
                        //已有认证资料

                    }else{
                        //认证资料
                        $add_authentic_data = [
                            'order_id'=>$order_id,
                            'certify_id'=>'1',
                            'status'=>'1',
                            'cert_no'=>$cert_no,
                            'cert_name'=>$member_data['cert_name'],
                            'idcard_front'=>$member_data['idcard_front'],
                            'idcard_back'=>$member_data['idcard_back'],
                            'create_time'=>date('Y-m-d H:i:s')
                        ];
                        //ceshi123
                        AuthenticLog::insert($add_authentic_data);
                    }
                    var_dump('id'.$order_id);
                    var_dump($i++);
                }
            }
            \Illuminate\Support\Facades\Log::debug('订单同步任务执行成功',$ressult);

        }else{ //提示

            \Illuminate\Support\Facades\Log::debug('订单同步任务执行失败',['订单同步任务执行失败']);
        }

    }


//    public function upload_img($fileName){
//        $fileUrl = 'https://img.tingxiangzu.com/'.$fileName;
//        // echo $fileUrl;
//        // dd(file_exists($fileUrl));
//        if(!empty($fileName)){
//            // echo $fileUrl."\r\n";
//            $file = file_get_contents($fileUrl);
//            $path = dirname(dirname(dirname(dirname(dirname(__FILE__)))) ). '/storage/tmp/'.$fileName;
//
//            file_put_contents($path,$file);
//            $uploud_res = AlipayService::upload($fileName,$path);
//            // print_r($uploud_res);
//            // dd($uploud_res);
//            if($uploud_res['status']){
//                if(file_exists($path)){
//                    unlink($path);
//                }
//            }
//        }
//
//    }

    public function upload_img($fileUrl){
        $path = parse_url($fileUrl, PHP_URL_PATH);

// 获取路径的文件信息
        $fileName = pathinfo($path, PATHINFO_BASENAME);
        if(!empty($fileName)){
            // echo $fileUrl."\r\n";
            $file = file_get_contents($fileUrl);
         $path = dirname(dirname(dirname(dirname(dirname(__FILE__)))) ). '/storage/tmp/'.$fileName;

            file_put_contents($path,$file);
            $uploud_res = AlipayService::upload($fileName,$path);
            return $fileName;
            // dd($uploud_res);

        }

    }


}
